<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			//根据课件动物类的例子，尝试定义更多的动物重写sound方法，比如：狗、猫等，至少3种。
			//创建一个动物类
			function Animal(type) {
				this.type = type;
			}
			//给动物类添加一个会叫的方法
			Animal.prototype.sound = function() {
				console.log(this.type + "会叫");
			}
			//创建一个空函数
			function F(){}
			//Animal的原型挂在这个空函数的原型上
			F.prototype = Animal.prototype;
			//创建一个小狗类
			function Dog(name){
				Animal.call(this,"小狗");
				this.name = name;
			}
			//子类的原型对象设为空函数的实例
			Dog.prototype = new F();
			//修复构造函数
			Dog.prototype.constructor = Dog;
			//重写叫声方法
			Dog.prototype.sound = function(){
				console.log(this.type + this.name + "在汪汪汪");
			}
			//实例化
			var dog = new Dog("敦敦");
			dog.sound();
			console.log(dog);
			
			//创建一个猫类
			function Cat(name){
				Animal.call(this,"小猫");
				this.name = name;
			}
			Cat.prototype = new F();
			Cat.prototype.constructor = Cat;
			Cat.prototype.sound = function(){
				console.log(this.type + this.name + "在喵喵喵");
			}
			var cat = new Cat("姜丝鸭");
			cat.sound();
			
			//创建一个小鱼类
			function Fish(){
				Animal.call(this,"小鱼");
			}
			Fish.prototype = new F();
			Fish.prototype.constructor = Fish;
			Fish.prototype.sound = function(){
				console.log(this.type + "在咕噜咕噜吐泡泡OoOo");
			}
			var fish = new Fish();
			fish.sound();
		</script>
	</body>
</html>
